home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_x / xcoral16.zip / XCORAL.C < prev    next >
C/C++ Source or Header  |  1993-01-15  |  5KB  |  203 lines

  1. /*
  2. ** Copyright 1989, 1992 by Lionel Fournigault
  3. **
  4. ** Permission to use, copy, and distribute for non-commercial purposes,
  5. ** is hereby granted without fee, providing that the above copyright
  6. ** notice appear in all copies and that both the copyright notice and this
  7. ** permission notice appear in supporting documentation.
  8. ** The software may be modified for your own purposes, but modified versions
  9. ** may not be distributed.
  10. ** This software is provided "as is" without any expressed or implied warranty.
  11. **
  12. **
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <signal.h>
  17. #include <X11/Xlib.h>
  18. #include <X11/cursorfont.h>
  19. #include <X11/Xutil.h>
  20. #include <X11/keysym.h>
  21. #include <sys/param.h>
  22. #include <strings.h>
  23.  
  24. #include "options.h"
  25. #include "xcoral.h"
  26. #include "browser.h"
  27. #include "flist.h"
  28.  
  29. Display        *dpy;
  30. EdWin        *TWin [MAXWIN], *edwin;     /* La table des fenetres */
  31. XContext    EdContext;            /* Pour switcher */
  32. static void    contHandler (), stopHandler ();
  33.  
  34.  
  35. /*
  36. **    Initialise les resources, les menus, les bouttons etc...
  37. **    Creer la premiere fenetre de texte et entre dans
  38. **    la boucle d'evenements.
  39. */
  40. main ( argc, argv ) 
  41. int argc;
  42. register char **argv;
  43. {
  44.     EdWin *CreateWindow ();
  45.     char pathname [MAXPATHLEN];
  46.     extern void exit ();
  47.     extern char  *getcwd();
  48.  
  49. #if defined(DEBUG) && defined(sparc)
  50.     malloc_debug(2);
  51.     malloc_verify();
  52. #endif
  53.     /*
  54.      * Ou suis-je dans quelle etagere.
  55.      */
  56.     if ( getcwd ( (char *) pathname, MAXPATHLEN + 2 ) == 0 ) {
  57.         (void) fprintf ( stderr, "Getwd error\n" );
  58.         (void) exit ( 1 );
  59.     }
  60.     (void) bzero ( (char *) TWin, MAXWIN );
  61.  
  62.     /*
  63.      * Initialisation du ressource manager, connexion avec le serveur,
  64.      * creation d'un contexte graphique pour le top et bottom shadow.
  65.      * Calcul des options ( parametres de la commande, .Xdefaults etc... )
  66.      */
  67.     XrmInitialize ();        
  68.     ParseOpenDisp ( &argc, argv );
  69.     CreateRGC ( dpy );
  70.     GetUserDatabase ();
  71.     MergeOptions ();
  72.  
  73.     EdContext = XUniqueContext ();
  74.  
  75.     /*
  76.       * Initialisation des ressources pour les elements Text,
  77.      * Menus et Panel de controle.
  78.      * Les ressources sont :
  79.      *     une fonte et 4 couleurs (foreground, background,
  80.      *    top_shadow et bottom shadow ).
  81.      */
  82.     InitTextRes ( dpy, GetOpFont ( OP_TEXT_FONT ), GetOpColor ( OP_TEXT_FG ),
  83.         GetOpColor ( OP_TEXT_BG ), GetOpColor ( OP_MENU_TS ),
  84.          GetOpColor ( OP_MENU_BS ));
  85.  
  86.     InitMenusRes ( dpy, GetOpFont ( OP_MENU_FONT ), GetOpColor ( OP_MENU_FG ),
  87.         GetOpColor ( OP_MENU_BG ), GetOpColor ( OP_MENU_TS ),
  88.          GetOpColor ( OP_MENU_BS ));
  89.  
  90.     InitControlRes ( GetOpColor ( OP_DIAL_FG ), GetOpColor ( OP_DIAL_BG ),
  91.         GetOpColor ( OP_DIAL_TS ),  GetOpColor ( OP_DIAL_BS ));
  92.  
  93.     /*
  94.      * Encore quelques initialisations.
  95.      */
  96.     InitEvent ();
  97.     InitScroll ( dpy );
  98.     InitKillBuf ();
  99.     InitBrowser ();
  100.         InitDialogWindow (); 
  101.     InitFileSelector ();
  102.     SetBrowserMode ( TEXT );
  103.     SetBrowserDir ( (char *) pathname );
  104.  
  105.     /*
  106.      * Allons-y pour la premiere fenetre d'edition. 
  107.      */
  108.     if ( (edwin = CreateWindow ()) == 0 ) { 
  109.         ( void ) fprintf ( stderr,"Create window error\n" );
  110.         (void) exit (1);
  111.     }
  112.     (void) strcpy ( edwin -> text -> filename, (char *) GetOpFilename () );
  113.     (void) strcpy ( edwin -> text -> current_dir, pathname );
  114.  
  115.     /*
  116.      * Si un nom de fichier est passe en argument on le charge
  117.      * dans la premiere fenetre de texte.
  118.      */    
  119.     if ( strcmp ( (char *) GetOpFilename (), "NoName" ) != NULL ) {
  120.         if ( LoadFile ( edwin -> text, (char *) GetOpFilename (), NEW ) == -1 ) {
  121.             XStoreName ( dpy, edwin -> w_frame, edwin -> text -> filename ); 
  122.             SetDirAndFilename ( edwin -> text,  (char *) GetOpFilename () );
  123.           }
  124.     }
  125.     
  126.     /*
  127.      * On ignore les signaux habituels, et on attrape le stop et
  128.      * le continue (pour des raisons tordues).
  129.      */
  130.     (void) signal ( SIGINT, SIG_IGN );
  131. #define DEBUG
  132. #ifndef DEBUG
  133.     (void) signal ( SIGQUIT, SIG_IGN );
  134. #endif DEBUG
  135. #undef DEBUG
  136.     (void) signal ( SIGTSTP, stopHandler );
  137.     (void) signal ( SIGCONT, contHandler );
  138.  
  139.     /* 
  140.      * Affichage de la premiere fenetre et on attend que les Events y se
  141.      * pointent.
  142.      */
  143.     XMapWindow ( dpy, edwin->w_frame );
  144.     XFlush ( dpy );
  145.     WaitForEvent ();
  146.  
  147.     /*NOTREACHED*/
  148. }
  149.  
  150. /*
  151. **    Name : stopHandler
  152. **
  153. **    Description : Attrape le signal 'stop'. S'il reste des requetes
  154. **        ou des    evenements on ignore le signal.
  155. **
  156. */
  157. static void stopHandler ()
  158. {
  159.  
  160. #ifdef DEBUG
  161.     (void) fprintf ( stderr, "Stop\n" );
  162. #endif DEBUG
  163.     (void) signal ( SIGTSTP, SIG_IGN );
  164.     XSync ( dpy, False );
  165.     if ( QLength ( dpy ) == 0 ) {    /* On peut stopper */
  166.         (void) signal ( SIGCONT, contHandler );
  167.         (void) signal ( SIGTSTP, SIG_DFL );
  168.         (void) kill ( getpid(), SIGTSTP );
  169.     }
  170.     else
  171.         (void) signal ( SIGTSTP,  stopHandler );
  172. }
  173.  
  174.  
  175. /*
  176. **    Name : contHandler 
  177. **
  178. **    Description : Attrape le signal 'continue' pour virer tous
  179. **        les evenements de type ButtonPress recus pendant que le
  180. **        process etait stoppe. 
  181. */
  182. static void contHandler ()
  183. {
  184.     XEvent event;
  185.  
  186. #ifdef DEBUG
  187.     (void) fprintf ( stderr, "Continue\n" );
  188. #endif DEBUG
  189.     (void) signal ( SIGCONT, SIG_IGN );
  190.  
  191.     XSync ( dpy, False );
  192.     if ( QLength ( dpy ) != 0 ) 
  193.         while ( XCheckMaskEvent ( dpy, ButtonPress, &event ));
  194.  
  195.     (void) signal ( SIGTSTP, stopHandler );
  196.     (void) signal ( SIGCONT, SIG_DFL );
  197.     (void) kill ( getpid (), SIGCONT );
  198.  
  199.     XRaiseWindow ( dpy, edwin -> w_frame );
  200.     XFlush ( dpy ); 
  201. }
  202.  
  203.